<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 */
namespace Common\Api;

use Common\Api\Api;
use Admin\Model\GamePrizegethisModel;

class GamePrizegethisApi extends Api{

		const FIND = "Common/GamePrizegethis/getInfo";
		const FINDS = "Common/GamePrizegethis/finds";
		const COUNT = "Common/GamePrizegethis/count";
		const ADD = "Common/GamePrizegethis/add";

    protected function _init(){
        $this -> model = new GamePrizegethisModel();
    }

    public function finds($gid,$p=1,$size=10){
        $where = array('h.game_id'=>$gid,'h.prize_type'=>array('neq',0));
        // dump($where);exit;
    	$r = $this->model->alias('h') //->cache(true)
    		->join(C('DB_PREFIX').'game_prize p ON h.prize_id = p.id')
            ->join('common_member m on h.uid=m.uid')
    		->where($where)->field('h.*,p.prize_name,m.nickname')
            ->page($p,$size)->order('h.get_time desc') -> select();

        $count = $this -> model ->alias('h')->where($where) -> count();// ->cache(true)
        // 查询满足要求的总记录数
        $Page = new \Think\Page($count, $size);
        $show = $Page -> show();

    	return $this->apiReturnSuc(array('list'=>$r,'show'=>$show));
    }
}